package cn.john.hrm.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MqListener {
    //定义邮件的队列名字
    public static final String QUEUE_NAME_EMAIL = "queue_name_email";
    //定义短信的队列名字
    public static final String QUEUE_NAME_SMS = "queue_name_SMS";
    //站内信队列
    public static final String QUEUE_NAME_SYSTEM_MESSAGE = "queue_name_system_message";
    //定义交换机
    public static final String EXCHANGE_NAME_TOPIC = "exchange_name_topic";
    //定义一个方法 用来监听发短信的对内
    @RabbitListener(queues = {QUEUE_NAME_SMS})
    public void sendMsg(String msg, Message message,Channel channel) throws IOException {
        //拿到消息
        //消费消息 调用短信服务 发送消息
        System.out.println("短信： 亲爱的用户您好! "+msg+"课程已经发布了，快来学习呀！");
        //确认签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
    @RabbitListener(queues = {QUEUE_NAME_EMAIL})
    public void sendEmail(String msg, Message message,Channel channel) throws IOException {
        //拿到消息
        //消费消息 调用短信服务 发送消息
        System.out.println("邮件： 亲爱的用户您好! "+msg+"课程已经发布了，快来学习呀！");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
    @RabbitListener(queues = {QUEUE_NAME_SYSTEM_MESSAGE})
    public void sendSysMsg(String msg, Message message,Channel channel) throws IOException {
        //拿到消息
        //消费消息 调用短信服务 发送消息
        System.out.println("站内信： 亲爱的用户您好! "+msg+"课程已经发布了，快来学习呀！");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
